package com.xgry.bpm.api.base.formltem.service.impl;

import com.xgry.bpm.api.base.formlist.entity.FormList;
import com.xgry.bpm.api.base.formltem.entity.FormLtem;
import com.xgry.bpm.api.base.formltem.mapper.FormLtemMapper;
import com.xgry.bpm.api.base.formltem.service.FormLtemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.apache.http.HttpStatus;

import java.util.List;

/**
* <p>
    * FormLtem服务实现类
    * </p>
*
* @author adrian
* @since 2020-07-07
*/
@Service
public class FormLtemServiceImpl extends ServiceImpl<FormLtemMapper, FormLtem>implements FormLtemService {

    @Override
    public int deleteById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        return baseMapper.deleteById(id);
    }

    @Override
    public FormLtem selectById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        FormLtem data=baseMapper.selectById(id);
        return data;
    }

    @Override
    public List<FormLtem>selectAll(FormLtem record){
        QueryWrapper<FormLtem>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        List<FormLtem>list=baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public IPage<FormLtem>selectPage(IPage<FormLtem> page , FormLtem record){
        // 查询条件
        QueryWrapper<FormLtem>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public IPage<FormLtem>getPage(IPage<FormLtem>page,QueryWrapper<FormLtem>queryWrapper){
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public void deleteByFormListId(Integer formListId) {
        List<FormLtem> list = baseMapper.selectList(new QueryWrapper<FormLtem>() {{
            this.eq("formListId", formListId);
        }});
        for (FormLtem formLtem : list) {
            baseMapper.deleteById(formLtem.getId());
        }

    }
}